//#include <ros/ros.h>
#include "../include/led/led_node.h"
#include <iostream>
#include <string>
#include <exception>
#include "../include/led/bx_dual_sdk.h"
#include "../include/led/iconv.h"
#include "../include/led/libcharset.h"
#include "../include/led/localcharset.h"
//#include "bucket_msgs/bucket_info.h"


#pragma comment(a, "bx_sdk_dual.a")

std::string ip_str;
unsigned char *ip = nullptr;
int port;
std::string font_path_str;
//unsigned char *font_path = nullptr;
//unsigned char font_path[] = "/home/sjx/agvscreen/src/gui/Fonts/simsun.ttc";
unsigned char font_path[] = "/home/lk/4-gen_screen4/install/share/gui/Fonts/simsun.ttc";

int led_dynamic_area_width;
int led_dynamic_area_height;
int led_grid_width;
int font_size;
int led_excel_left_top_x;
int led_excel_left_top_y;
int ping_color = 1;
int led_id;
bool led_on_agv;

void addProgram_G6();
void addArea_G6(Ouint16 AreaID, Ouint8 AreaType, Ouint16 AreaX, Ouint16 AreaY, Ouint16 AreaWidth, Ouint16 AreaHeight);
void addAreaTime_G6(Ouint16 AreaID);
void addAreaPicture_G6(Ouint16 AreaID, Ouint8 str[]);
void addAreaPicturePic_G6(Ouint16 AreaID);
void tcp_send_program_G6(Ouint8 *ip, Ouint16 port);
void dynamic_6(Ouint8 *ip, int cmb_ping_Color);

void onbonTest_Dynamic_6G_Pic();

void addProgram_G6()
{
	EQprogramHeader_G6 pHeader;
	pHeader.FileType = 0x00;
	pHeader.ProgramID = 0;
	pHeader.ProgramStyle = 0x00;
	pHeader.ProgramPriority = 0x00;
	pHeader.ProgramPlayTimes = 1;
	pHeader.ProgramTimeSpan = 0;
	pHeader.SpecialFlag = 0;
	pHeader.CommExtendParaLen = 0x00;
	pHeader.ScheduNum = 0;
	pHeader.LoopValue = 0;
	pHeader.Intergrate = 0x00;
	pHeader.TimeAttributeNum = 0x00;
	pHeader.TimeAttribute0Offset = 0x0000;
	pHeader.ProgramWeek = 0xff;
	pHeader.ProgramLifeSpan_sy = 0xffff;
	pHeader.ProgramLifeSpan_sm = 0x03;
	pHeader.ProgramLifeSpan_sd = 0x14;
	pHeader.ProgramLifeSpan_ey = 0xffff;
	pHeader.ProgramLifeSpan_em = 0x03;
	pHeader.ProgramLifeSpan_ed = 0x14;
	//pHeader.PlayPeriodGrpNum=0;

	bxDual_program_addProgram_G6(&pHeader);
}

void addArea_G6(Ouint16 AreaID, Ouint8 AreaType, Ouint16 AreaX, Ouint16 AreaY, Ouint16 AreaWidth, Ouint16 AreaHeight)
{
	Ouint16 nAreaID = AreaID;
	EQareaHeader_G6 aHeader1;
	aHeader1.AreaType = AreaType;
	aHeader1.AreaX = AreaX;
	aHeader1.AreaY = AreaY;
	aHeader1.AreaWidth = AreaWidth;
	aHeader1.AreaHeight = AreaHeight;
	aHeader1.BackGroundFlag = 0x00;
	aHeader1.Transparency = 101;
	aHeader1.AreaEqual = 0x00;
	bxDual_program_addArea_G6(nAreaID, &aHeader1);
}

void addAreaTime_G6(Ouint16 AreaID)
{
	EQtimeAreaData_G56 timeData;
	timeData.linestyle = eMULTILINE;
	timeData.color = eGREEN;
	timeData.fontName = (Ouint8 *)malloc(sizeof(Ouint8) * 40);
	strcpy((Oint8 *)timeData.fontName, "����");
	timeData.fontSize = 12;
	timeData.fontBold = 0;
	timeData.fontItalic = 0;
	timeData.fontUnderline = 0;
	timeData.fontAlign = 1; //0--�����???1-���У�2-�Ҷ���
	timeData.date_enable = true;
	timeData.datestyle = (E_DateStyle)eYYYY_MM_DD_CHS; //eMM_DD_CHS;// //eYYYY_MM_DD_VIRGURE;//
	timeData.week_enable = false;
	timeData.weekstyle = (E_WeekStyle)eMonday_CHS;
	timeData.time_enable = true;
	timeData.timestyle = (E_TimeStyle)eHH_MM_SS_COLON;
	bxDual_program_timeAreaAddContent_G6(AreaID, &timeData);
}

void addAreaPicture_G6(Ouint16 AreaID, Ouint8 str[])
{
	Ouint8 *str1 = (Ouint8 *)str;
	EQpageHeader_G6 pheader1;
	pheader1.PageStyle = 0x00;
	pheader1.DisplayMode = 0x01; //静�??
	pheader1.ClearMode = 0x01;
	pheader1.Speed = 1;
	pheader1.StayTime = 20000;
	pheader1.RepeatTime = 1;
	pheader1.ValidLen = 1;
	pheader1.CartoonFrameRate = 0x00;
	pheader1.BackNotValidFlag = 0x00;
	pheader1.arrMode = eMULTILINE; //eMULTILINE;//
	pheader1.fontSize = 10;
	pheader1.color = E_Color_G56::eRED; // E_Color_G56
	pheader1.fontBold = true;
	pheader1.fontItalic = true;
	pheader1.tdirection = pNORMAL;
	pheader1.txtSpace = 0;
	pheader1.Valign = 0;
	pheader1.Halign = 0;

	bxDual_program_picturesAreaAddTxt_G6(AreaID, str1, (Ouint8 *)"/home/sjx/Desktop/led_ws/src/Fonts/simsun.ttc", &pheader1);
	//program_fontPath_picturesAreaAddTxt_G6(0,str,(Ouint8*)"C:/Windows/Fonts/simsun.ttc",&pheader1);
}

void addAreaPicturePic_G6(Ouint16 areaID)
{
	EQpageHeader_G6 pheader;
	pheader.PageStyle = 0x00;
	pheader.DisplayMode = 0x03;
	pheader.ClearMode = 0x01;
	pheader.Speed = 15;
	pheader.StayTime = 500;
	pheader.RepeatTime = 1;
	pheader.ValidLen = 0;
	pheader.CartoonFrameRate = 0x00;
	pheader.BackNotValidFlag = 0x00;
	pheader.arrMode = E_arrMode::eSINGLELINE;
	pheader.fontSize = 10;
	pheader.color = E_Color_G56::eRED;
	pheader.fontBold = 0;
	pheader.fontItalic = 0;
	pheader.tdirection = E_txtDirection::pNORMAL;
	pheader.txtSpace = 0;
	pheader.Valign = 2;
	pheader.Halign = 2;
	Ouint8 *img = (Ouint8 *)"F:/work github/Debug HUB/BX-V-VI/bx.dual.cplus/src/lib/2Led0_0.png";
	int err = bxDual_program_pictureAreaAddPic_G6(areaID, 0, &pheader, img);
}

void tcp_send_program_G6(Ouint8 *ip, Ouint16 port)
{
	Oint8 ret;
	EQprogram_G6 program;
	memset((void *)&program, 0, sizeof(program));
	bxDual_program_IntegrateProgramFile_G6(&program);

	ret = bxDual_cmd_ofsStartFileTransf(ip, port);
	printf("ret =====cmd_ofsStartFileTransf===== %d \n", ret);
	if (ret != 0)
	{
		printf("cmd_ofsStartFileTransf run error...");
	}
	else
	{
		printf("cmd_ofsStartFileTransf run succeed...");
	}

	ret = bxDual_cmd_ofsWriteFile(ip, port, program.dfileName, program.dfileType, program.dfileLen, 1, program.dfileAddre);
	if (ret != 0)
	{
		printf("cmd_ofsWriteFile run error...");
	}
	else
	{
		printf("cmd_ofsWriteFile run succeed...");
	}
	printf("ret =====cmd_ofsWriteFile===== %d \n", ret);

	ret = bxDual_cmd_ofsWriteFile(ip, port, program.fileName, program.fileType, program.fileLen, 1, program.fileAddre);
	if (ret != 0)
	{
		printf("cmd_ofsWriteFile run error...");
	}
	else
	{
		printf("cmd_ofsWriteFile run succeed...");
	}
	printf("ret =====cmd_ofsWriteFile===== %d \n", ret);

	ret = bxDual_cmd_ofsEndFileTransf(ip, port);
	if (ret != 0)
	{
		printf("cmd_ofsEndFileTransf run error...");
	}
	else
	{
		printf("cmd_ofsEndFileTransf run succeed...");
	}
	printf("ret =====cmd_ofsEndFileTransf===== %d \n", ret);

	//ɾ�������ڴ��еĽ�Ŀ
	bxDual_program_deleteProgram_G6();
	bxDual_program_freeBuffer_G6(&program);
}
//��̬��
void dynamic_6(Ouint8 *ip, int cmb_ping_Color)
{
	Ouint8 DisplayMode = 0x02; //��ʾ��ʽ:  0x00 �C������? 0x01 �C��ֹ��ʾ 0x02 �C���ٴ��??? 0x03 �C�����ƶ� 0x04 �C�������� 0x05 �C�����ƶ� 0x06 �C�������� 0x07 �C��˸ ......
							   //0x25 �C�����ƶ�  0x26 �C��������  0x27 �C�����ƶ�  0x28 �C��������

	Ouint8 ClearMode = 0;	//�˳���ʽ/������ʽ: ÿһҳ���˳���ʽ��
	Ouint8 Speed = 8;		//�ٶȵȼ�
	Ouint16 StayTime = 200; //ͣ��ʱ�䣬��λΪ 10ms
	Ouint8 RepeatTime = 3;
	//PageStyle End.

	//��ʾ���ݺ�������? begin----------------------------------------------
	EQfontData oFont;
	oFont.arrMode = eMULTILINE;
	oFont.fontSize = 10;
	oFont.color = eRED;
	oFont.fontBold = false;
	oFont.fontItalic = false;
	oFont.tdirection = pNORMAL;
	oFont.txtSpace = 0;
	oFont.Halign = 1;
	oFont.Valign = 2;
	Ouint8 *fontName = (Ouint8 *)"/home/sjx/Desktop/led_ws/src/Fonts/simsun.ttc";

	oFont.arrMode = eSINGLELINE; // eMULTILINE;//;
								 //oFont.fontSize = 8;
	onbon_DynamicAreaInfo_G6 oTxtInfo;
	oTxtInfo.nType = 2;
	oTxtInfo.DisplayMode = DisplayMode;
	oTxtInfo.ClearMode = ClearMode;
	oTxtInfo.Speed = Speed;
	oTxtInfo.StayTime = StayTime;
	oTxtInfo.RepeatTime = RepeatTime;
	oTxtInfo.fontName = fontName;
	oTxtInfo.oFont = oFont;

	oTxtInfo.filePath = (Ouint8 *)"/home/sjx/Desktop/led_ws/src/led_ros/pic/123.png"; //(Ouint8*)"T1-0123456789-abcdefghijklmnopqrst-����|";
	const Ouint8 cnst_InfoCount = 1;												  //���������ж��ٸ����ݵ�Ԫ����
	onbon_DynamicAreaInfo_G6 stDynamicAreaBaseInfo_6G[cnst_InfoCount];
	stDynamicAreaBaseInfo_6G[0] = oTxtInfo;
	Ouint8 uAreaId = 0;

	Ouint8 RunMode = 0x00;
	Ouint16 Timeout = 3;	  //Timeout 2 ��̬�����ݳ�ʱʱ�䣬��λΪ��
	Ouint8 RelateAllPro = 0;  //RelateAllPro 1 �����ֽ�Ϊ 1 ʱ�������첽��Ŀ����ʱ���������Ÿö�̬����Ϊ 0 ʱ���ɽ������Ĺ���������
	Ouint16 RelateProNum = 0; //��̬��������˶��ٸ��첽��Ŀһ��������ĳ���첽��Ŀ���򵱸��첽��Ŀ����ʱ�������Ÿö��?���򣬷��򣬲��������Ÿö�̬�������µĽ�Ŀ��Ÿ�������??? RelateProNum ��ֵ��ȷ��������ֵΪ 0 ʱ�����ͣ�
	Ouint16 *RelateProSerial = NULL;
	Ouint8 ImmePlay = 1; //1 �Ƿ��������Ÿ��ֽ�Ϊ 0 ʱ���ö�̬�������첽��Ŀһ�𲥷ţ����ֽ�Ϊ 1 ʱ���첽��Ŀֹͣ���ţ������Ÿö�̬������ֽ�???; Ϊ 2 ʱ���ݴ�ö��?���򣬵��������Ŀ�����ߵ��첽��Ŀ�󲥷Ÿö��?����ע�⣺�����ֽ�Ϊ 0 ʱ��RelateAllPro ��RelateProSerialN-1 �Ĳ�������Ч��������Ч���ò���Ϊ 1 �� 2 ʱ�����ڲ����첽��Ŀͬʱ���ţ�Ϊ���Ƹö�̬�����ܼ�ʱ��������ѡ��RunMode ����Ϊ 2 �� 4����ȻҲ
	Ouint16 uAreaX = 0;
	Ouint16 uAreaY = 0;
	Ouint16 uWidth = 64;
	Ouint16 uHeight = 32;
	//EQareaframeHeader oFrame;
	BxAreaFrmae_Dynamic_G6 oFrame;
	oFrame.AreaFFlag = 0; //�߿�Ĭ���ޱ߿�
	oFrame.pStrFramePathFile = (Ouint8 *)"/home/sjx/Desktop/led_ws/src/led_ros/pic/0.png";

	EQscreenframeHeader_G6 oFrameHeader;
	oFrameHeader.FrameDispStype = 0x01;
	oFrameHeader.FrameDispSpeed = 0x10;
	oFrameHeader.FrameMoveStep = 0x01;
	oFrameHeader.FrameUnitLength = 32;
	oFrameHeader.FrameUnitWidth = 4; //2;
	oFrameHeader.FrameDirectDispBit = 0x01;

	oFrame.oAreaFrame = oFrameHeader;

	//������������/����������ݽ�???
	BXSound_6G oSoundG6;
	Ouint8 *strSoundTxt = (Ouint8 *)"��̬�������������ֺ�ͼƬ�ӿڷ���";
	Ouint8 nSize = sizeof(strSoundTxt);
	Ouint8 nStrLen = strlen((const char *)strSoundTxt);
	{
		oSoundG6.SoundFlag = 0x00;			  //1 0x00 �Ƿ�ʹ����������;0 ��ʾ��ʹ������; 1 ��ʾ����������;
		oSoundG6.SoundPerson = 0x01;		  //1 0x00 ������ ��ֵ��Χ�� 0 - 5���� 6 ��ѡ��ֻ�� SoundFlag���Ƿ�ʹ���������ţ�Ϊ 1 ʱ�ŷ��͸��ֽڣ����򲻷��͸�ֵĬ��Ϊ 0
		oSoundG6.SoundVolum = 1;			  //1 0x05 ������ֵ��Χ�� 0~10���� 11 �֣�0��ʾ����ֻ�� SoundFlag���Ƿ�ʹ���������ţ�Ϊ 1 ʱ�ŷ��͸��ֽڣ����򲻷��͸�ֵĬ��Ϊ 5
		oSoundG6.SoundSpeed = 0x2;			  //1 0x05 ���ٸ�ֵ��Χ�� 0~10���� 11 ��ֻ�� SoundFlag���Ƿ�ʹ���������ţ�Ϊ 1 ʱ�ŷ��͸��ֽڣ����򲻷��͸�ֵĬ��Ϊ 5
		oSoundG6.SoundDataMode = 0x00;		  //1 0x00 SoundData �ı����ʽ����ֵ�������£�???0x00 GB2312; 0x01 GBK; 0x02 BIG5; 0x03 UNICODEֻ�� SoundFlag���Ƿ�ʹ���������ţ�Ϊ 1 ʱ�ŷ��͸��ֽڣ����򲻷���
		oSoundG6.SoundReplayTimes = 0x01;	  // 0xffffffff;	//4 0x00000000 �ز�������ֵΪ 0����ʾ���� 1 �θ�ֵΪ 1����ʾ���� 2 ��
											  //......
											  //��ֵΪ 0xffffffff����ʾ�������޴�ֻ�� SoundFlag���Ƿ�ʹ���ﲥ�ţ�Ϊ 1 ʱ�ŷ��͸��ֽڣ����򲻷��͸�ֵĬ��Ϊ 0
		oSoundG6.SoundReplayDelay = 200;	  //4 0x00000000 �ز�ʱ������ֵ��ʾ���β���������ʱ��������λΪ 10msֻ�� SoundFlag���Ƿ�ʹ���������ţ�Ϊ 1 ʱ�ŷ��͸��ֽڣ����򲻷��͸�ֵĬ��Ϊ 0
		oSoundG6.SoundReservedParaLen = 0x03; //1 0x03 ��������������������
		oSoundG6.Soundnumdeal = 0x00;		  //1 0 0���Զ��ж�1�����������봦�� 2����������ֵ����ֻ�е� SoundFlag Ϊ 1 ��SoundReservedParaLen��Ϊ 0�ŷ��ʹ˲���
		oSoundG6.Soundlanguages = 0x00;		  // 1 0 0���Զ��ж�����1�����������֡�������λ��������ŵȺϳ��?����2�����������֡�������λ��������ŵȺϳ��?Ӣ��ֻ�е� SoundFlag Ϊ 1 �� SoundReservedParaLen��Ϊ 0�ŷ��ʹ˲�����Ŀǰֻ֧����Ӣ�ģ�
		oSoundG6.Soundwordstyle = 0x00;		  // 1 0 0���Զ��жϷ�����ʽ1����ĸ������ʽ2�����ʷ�����ʽֻ�е� SoundFlag Ϊ 1 ��SoundReservedParaLen��Ϊ 0�ŷ��ʹ˲���
		oSoundG6.SoundDataLen = nStrLen;	  // 4 �������ݳ���; ֻ�� SoundFlag���Ƿ�ʹ���������ţ�Ϊ 1 ʱ�ŷ��͸��ֽڣ����򲻷���
		oSoundG6.SoundData = strSoundTxt;	  // N ��������ֻ�� SoundFlag���Ƿ�ʹ���������ţ�Ϊ 1 ʱ�ŷ��͸��ֽڣ����򲻷���
	}

	int nSendInfoCount = cnst_InfoCount;
	nSendInfoCount = 1;
	//bxDual_dynamicArea_SetDualPixel(eDOUBLE_COLOR_PIXTYPE_1);
	int nRet = bxDual_dynamicArea_AddAreaInfos_6G_V2(ip, 5005, (E_ScreenColor_G56)cmb_ping_Color,
													 uAreaId,
													 RunMode,
													 Timeout,
													 RelateAllPro,
													 RelateProNum,
													 RelateProSerial,
													 ImmePlay,
													 uAreaX, uAreaY, uWidth, uHeight,
													 oFrame,
													 nSendInfoCount,
													 stDynamicAreaBaseInfo_6G,
													 &oSoundG6);
}

void onbonTest_Dynamic_6G_Pic()
{

  unsigned char pIP[16] = "192.168.60.10";
	Ouint32 nPort = 5005;

	Ouint16 nAreaID = 0;
	E_ScreenColor_G56 eColor = E_ScreenColor_G56::eSCREEN_COLOR_DOUBLE; // eSCREEN_COLOR_THREE;

	EQpageHeader_G6 stPageHeader;
	stPageHeader.PageStyle = 0x00;
	stPageHeader.DisplayMode = 0x04;
	stPageHeader.ClearMode = 0x00;
	stPageHeader.Speed = 64;
	stPageHeader.StayTime = 0; // 500;
	stPageHeader.RepeatTime = 1;
	stPageHeader.ValidLen = 64;
	stPageHeader.CartoonFrameRate = 0x00;
	stPageHeader.BackNotValidFlag = 0x00;
	stPageHeader.arrMode = eSINGLELINE; //eMULTILINE;//
	stPageHeader.fontSize = 10;
	stPageHeader.color = eRED;
	stPageHeader.fontBold = false;
	stPageHeader.fontItalic = false;
	stPageHeader.tdirection = pNORMAL;
	stPageHeader.txtSpace = 0;
	stPageHeader.Valign = 1;
	stPageHeader.Halign = 1;

	stPageHeader.DisplayMode = 0x01;

	//bxDual_dynamicArea_DelArea_6G(pIP, 5005, 0xff);

	bxDual_dynamicArea_AddAreaPic_6G(pIP, 5005, eColor, nAreaID, 0, 0, 288, 192, &stPageHeader, (Ouint8 *)"F:/work github/Debug HUB/BX-V-VI/bx.dual.cplus/src/lib/2Led0_0.png");

	//dynamicArea_DelArea_6G(pIP, 5005, 0xff);
	//dynamicAreaS_AddAreaPic_6G
	//dynamicArea_AddAreaPic_6G(pIP, 5005, eColor, nAreaID, 16 + 32 + 1, 0, 32, 32, &stPageHeader, (Ouint8*)"./ͼƬ�����ļ�/��������.bmp");
}

void dynamic_6_txtWithProgram_1(Ouint8 *ip, Ouint32 nPort, E_ScreenColor_G56 baseColor, E_Color_G56 color,
								Ouint16 fontSize, Ouint8 areaId,
								Ouint16 AreaX, Ouint16 AreaY, Ouint16 AreaWidth, Ouint16 AreaHeight,
								Ouint8 *Txt)
{
  BXSound_6G stSoundData;
    stSoundData.SoundFlag = 0;
    stSoundData.SoundPerson = 0x01;
    stSoundData.SoundVolum = 0;
    stSoundData.SoundSpeed = 0;
    stSoundData.SoundDataMode = 0x01;
    stSoundData.SoundReplayTimes = 0;
    stSoundData.SoundReplayDelay = 0;
    stSoundData.SoundReservedParaLen = 3;
    stSoundData.Soundnumdeal = 0;
    stSoundData.Soundlanguages = 0;
    stSoundData.Soundwordstyle = 0;
    stSoundData.SoundDataLen = 0;
    stSoundData.SoundData = nullptr;

    EQareaHeader_G6 oAreaHeader_G6;
    oAreaHeader_G6.AreaType = 0x10;			//区域类型；动态区时，固定为0x10;
    oAreaHeader_G6.AreaX = AreaX;			//区域左上角横坐标
    oAreaHeader_G6.AreaY = AreaY;			//区域左上角纵坐标
    oAreaHeader_G6.AreaWidth = AreaWidth;	//区域宽度
    oAreaHeader_G6.AreaHeight = AreaHeight; //区域高度
    oAreaHeader_G6.BackGroundFlag = 0;		//是否有背景
    oAreaHeader_G6.Transparency = 101;		//透明度
    oAreaHeader_G6.AreaEqual = 0;			//前景、背景区域大小是否相同
    oAreaHeader_G6.stSoundData = stSoundData;

    EQpageHeader_G6 stPageHeader;
    stPageHeader.PageStyle = 0x00;	   //数据页类型
    stPageHeader.DisplayMode = 0x04;   //显示方式:0x00 –随机显示; 0x01–静止显示; 0x02–快速打出; 0x03–向左移动; 0x04 –向左连移; ... 0x25 –向右移动  0x26 –向右连移  0x27 –向下移动  0x28 –向下连移
    stPageHeader.ClearMode = 0;		   //退出方式/清屏方式
    stPageHeader.Speed = 30;		   //速度等级
    stPageHeader.StayTime = 200;	   //停留时间
    stPageHeader.RepeatTime = 1;	   //重复次数
    stPageHeader.ValidLen = 0;		   //此字段只在左移右移方式下有效
    stPageHeader.CartoonFrameRate = 0; //特技为动画方式时，该值代表其帧率
    stPageHeader.BackNotValidFlag = 0; //背景无效标志
    //字体信息-------------------------------------------------------------------------------------------------------
    stPageHeader.arrMode = E_arrMode::eMULTILINE;	   //排列方式--单行多行
    stPageHeader.fontSize = fontSize;				   //字体大小
    stPageHeader.color = color;						   //字体颜色 E_Color_G56此通过此枚举值可以直接配置七彩色，如果大于枚举范围使用RGB888模式
    stPageHeader.fontBold = 0;						   //是否为粗体
    stPageHeader.fontItalic = 0;					   //是否为斜体
    stPageHeader.tdirection = E_txtDirection::pNORMAL; //文字方向
    stPageHeader.txtSpace = 0;						   //文字间隔
    stPageHeader.Halign = 2;						   //横向对齐方式（0系统自适应、1左对齐、2居中、3右对齐）
    stPageHeader.Valign = 2;						   //纵向对齐方式（0系统自适应、1上对齐、2居中、3下对齐）

    Ouint8 *fontName = (Ouint8 *)font_path;
    Ouint8 *strAreaTxtContent = (Ouint8 *)Txt;

    Ouint16 RelateProNum = 0; //关联所有节目
    Ouint16 *RelateProSerial = nullptr;

    EQprogram_G6 program;
    memset((void *)&program, 0, sizeof(program));
    int ret = bxDual_program_IntegrateProgramFile_G6(&program);
    bxDual_program_deleteProgram_G6();
    ret = bxDual_program_freeBuffer_G6(&program);
    std::cout << "ret3 = " << ret << std::endl;
    // Ouint8* pIP, Ouint32 nPort, E_ScreenColor_G56 color, Ouint8 uAreaId, EQareaHeader_G6* oAreaHeader_G6,
    // EQpageHeader_G6* stPageHeader, Ouint8* fontName, Ouint8* strAreaTxtContent, Ouint16 RelateProNum, Ouint16* RelateProSerial
    ret = bxDual_dynamicArea_AddAreaTxtDetails_WithProgram_6G(ip, nPort, (E_ScreenColor_G56)baseColor,
                              areaId,
                              &oAreaHeader_G6,
                              &stPageHeader,
                              fontName,
                              strAreaTxtContent,
                              RelateProNum,
                              RelateProSerial);
    std::cout << "ret4 = " << ret << std::endl;
}

void agvInfoShowCb(const agv_msgs::led_show::ConstPtr &msg)
{
	static bool first_msg = true;
	if (first_msg)
	{
		first_msg = false;
		bxDual_dynamicArea_DelArea_6G(ip, port, 0); //删除指定id的动态区
	}

	try
	{
		Ouint8 *ip = (unsigned char *)msg->ip.data();
		Ouint8 *txt = (unsigned char *)msg->txt.data();
		dynamic_6_txtWithProgram_1(
			ip,
			msg->port,
			(E_ScreenColor_G56)ping_color,
			E_Color_G56(msg->color),
			msg->font,
			msg->id,
			msg->left_top_x,
			msg->left_top_y,
			msg->width,
			msg->height,
			txt);
	}
	catch (std::exception &e)
	{
		std::cout << e.what() << std::endl;
	}
	// std::cout << "\n\taasdfadfasdfds" << std::endl;
}


void agvInfoShowled(uint8_t *ip, uint32_t nPort, uint8_t baseColor, uint8_t color,
                    uint16_t fontSize, uint8_t areaId,
                    uint16_t AreaX, uint16_t AreaY, uint16_t AreaWidth, uint16_t AreaHeight,
                    uint8_t *txt)
{
//    Ouint8 *ip = (unsigned char *)Ip.data();
//    Ouint8 *txt = (unsigned char *)Txt.data();

//    int ret = bxDual_dynamicArea_DelArea_6G(ip, nPort, 0);
//    std::cout << "ret = " << ret << std::endl;


    dynamic_6_txtWithProgram_1(
      ip,
      nPort,
      (E_ScreenColor_G56)baseColor,
      E_Color_G56(color),
      fontSize,
      areaId,
      AreaX,
      AreaY,
      AreaWidth,
      AreaHeight,
      txt);

//    std::cout << "ret = " << ret << std::endl;

}


uint8_t delete_programFile(Ouint8 *ip, Ouint16 port)
{
	Oint8 ret;
	GetDirBlock_G56 dirBlock;
	dirBlock.fileNumber = 0;
	dirBlock.fileType = 0;
	dirBlock.dataAddre = NULL;
	ret = bxDual_cmd_ofsReedDirBlock(ip, port, &dirBlock);

	int nRet = 0;
	FileAttribute_G56 fileAttr;
	for (int i = 0; i < dirBlock.fileNumber; i++)
	{
		memset((void *)&fileAttr, 0, sizeof(fileAttr));
		ret = bxDual_cmd_getFileAttr(&dirBlock, i, &fileAttr);
		nRet = bxDual_cmd_ofsDeleteFormatFile(ip, port, 1, fileAttr.fileName);
	}

	ret = bxDual_cmd_ofs_freeDirBlock(&dirBlock);
	return ret;
}

void delete_dynamic_areas()
{
	for (int i = 0; i < 32; i++)
	{
    int ret  = bxDual_dynamicArea_DelArea_6G(ip, port, i);
//      std::cout << "bxDual2:" <<ret <<std::endl;
	}
}

int led_board_init(void)
{
  //获取控制板基本参数
  int ret = 0;
  Ping_data retdata;


//  <arg name="ip" default="192.168.0.198"/> <!-- led ip -->
//  <arg name="port" default="5005"/> <!-- led port -->
//  <arg name="led_dynamic_area_width" default="16"/> <!-- (动态区域)字体宽度，单位为led像素 -->
//  <arg name="led_dynamic_area_height" default="16"/> <!-- (动态区域)字体高度，单位为led像素 -->
//  <arg name="led_font_size" default="10"/> <!-- 字体大小 -->
//  <arg name="led_excel_left_top_x" default="3"/> <!-- 表格左上角坐标(第一个单元格字体起点)之x -->
//  <arg name="led_excel_left_top_y" default="15"/> <!-- 表格左上角坐标(第一个单元格字体起点)之y -->
//  <arg name="led_grid_width" default="21"/> <!-- 单元格宽度, 即左上角第一个单元格右侧线的x值 -->
//  <arg name="font_path" default="/home/lk/led_ws/install/share/led/Fonts/simsun.ttc"/>
//  <arg name="led_id" default="0"/>

  unsigned char ip[] = "192.168.60.10";
  unsigned short port = 5005;
  ret = bxDual_cmd_tcpPing(ip, port, &retdata);

  std::cout << "ret:" << ret << std::endl;

  if (retdata.Color == 1)
  {
    ping_color = 1;
  }
  else if (retdata.Color == 3)
  {
    ping_color = 2;
  }
  else if (retdata.Color == 7)
  {
    ping_color = 3;
  }
  else
  {
    ping_color = 4;
  }

  std::cout << "IP:" <<ping_color <<std::endl;
  ret = bxDual_program_setScreenParams_G56((E_ScreenColor_G56)ping_color, retdata.ControllerType, eDOUBLE_COLOR_PIXTYPE_1);

  std::cout << "bxDual:" <<ret <<std::endl;

  ret  = delete_programFile(ip, port); //删除所有节目
//    std::cout << "bxDual1:" <<ret <<std::endl;
  delete_dynamic_areas();

}

